package com.ayuer.chapter07;

import java.util.HashMap;

public class NoRepeatSubString {
    public static void main(String[] args) {
        //"abcabcbb"
        String str = "abba";
        int begin = 0;
        int maxLen = 0;
        HashMap<Character, Integer> map = new HashMap<>();
        for (int end = 0; end < str.length(); end++) {
            char ch = str.charAt(end);
            if (map.containsKey(ch)) {
                //存在
                begin = Math.max(map.get(ch) + 1, begin);
            }
            map.put(ch, end);
            maxLen = Math.max(end - begin + 1, maxLen);
            System.out.println(str.substring(begin, end + 1));
        }
        System.out.println(maxLen);
    }
}
